<template>
  <div class="login">
    <div class="login-input">
      <div class="login-title">登录</div>
      <el-input
        class="news-input"
        v-model="user"
        placeholder="请输入账号"
        size="large"
        clearable
      >
        <template #prefix>
          <el-icon class="el-input__icon" :size="22"><User /></el-icon>
        </template>
      </el-input>
      <el-input
        class="news-input"
        v-model="password"
        type="password"
        placeholder="请输入密码"
        size="large"
        show-password
        clearable
      >
        <template #prefix>
          <el-icon class="el-input__icon" :size="22"><Lock /></el-icon>
        </template>
      </el-input>
      <el-button type="primary" size="large" class="btn" @click="Login"
        >登录</el-button
      >
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { User, Lock } from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";

const Router = useRouter();
const user = ref();
const password = ref();

const Login = () => {
  if (!user.value) {
    return ElMessage({
      type: "error",
      message: "请输入用户名",
    });
  }
  if (!password.value) {
    return ElMessage({
      type: "error",
      message: "请输入密码",
    });
  }
  if (user.value === "admin" && password.value === "123456") {
    sessionStorage.setItem(
      "login",
      encodeURIComponent(JSON.stringify({ value: true }))
    );
    Router.push({
      path: "/",
    });
  } else {
    return ElMessage({
      type: "error",
      message: "用户名或密码错误",
    });
  }
};
</script>
<style>
.login {
  height: 100vh;
  background-color: #2362af;
}

.login-input {
  width: 500px;
  text-align: center;
  margin: auto;
  padding-top: 160px;
}

.login-title {
  font-size: 26px;
  font-weight: 600;
  color: #ffffff;
  height: 40px;
}

.news-input {
  width: 460px;
  height: 50px;
  margin-bottom: 20px;
}

.btn {
  width: 460px;
}
</style>
